package com.yanfan.ba.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;

import com.yanfan.ba.mapper.IbmsBaDataMapper;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.ba.domain.IbmsBaData;
import com.yanfan.ba.service.IIbmsBaDataService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * BA设备数据Controller
 *
 * @author genluo
 * @date 2024-09-22
 */
@Api(tags = "BA设备数据")
@RestController
@RequestMapping("/ba/data")
public class IbmsBaDataController extends BaseController {
    @Autowired
    private IIbmsBaDataService ibmsBaDataService;

    @Autowired
    private IbmsBaDataMapper ibmsBaDataMapper;

    /**
     * 查询BA设备数据列表
     */
    @ApiOperation("BA设备数据分页列表")
    @PreAuthorize("@ss.hasPermi('ba:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(IbmsBaData ibmsBaData) {
        startPage();
        List<IbmsBaData> list = ibmsBaDataService.queryPageList(ibmsBaData);
//        for (IbmsBaData baData : list) {
//            String name = baData.getName();
//            int secondDotIndex = name.indexOf('.', name.indexOf('.') + 1); // 获取第二个点的位置
//            int thirdDotIndex = name.indexOf('.', secondDotIndex + 1); // 获取第三个点的位置
//            int fifthDotIndex = name.indexOf('.', name.indexOf('.', name.indexOf('.', name.indexOf('.') + 1) + 1) + 1); // 获取第五个点的位置
//            int sixthDotIndex = name.indexOf('.', fifthDotIndex + 1); // 获取第六个点的位置
//            // 截取第二个点之后与第三个点之前的数据
//            String data1 = name.substring(secondDotIndex + 1, thirdDotIndex);
//            // 截取第五个点之后与第六个点之前的数据
//            String data2 = name.substring(fifthDotIndex + 1, sixthDotIndex);
//            baData.setName(data2);
//        }
        return getDataTable(list);
    }

    /**
     * 导出BA设备数据列表
     */
    @ApiOperation("导出BA设备数据列表")
    @PreAuthorize("@ss.hasPermi('ba:data:export')")
    @Log(title = "BA设备数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IbmsBaData ibmsBaData) {
        List<IbmsBaData> list = ibmsBaDataService.queryPageList(ibmsBaData);
        ExcelUtil<IbmsBaData> util = new ExcelUtil<IbmsBaData>(IbmsBaData.class);
        util.exportExcel(response, list, "BA设备数据数据");
    }

    /**
     * 获取BA设备数据详细信息
     */
    @ApiOperation("获取BA设备数据详细信息")
    @PreAuthorize("@ss.hasPermi('ba:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ibmsBaDataService.getById(id));
    }

    /**
     * 新增BA设备数据
     */
    @ApiOperation("新增BA设备数据")
    @PreAuthorize("@ss.hasPermi('ba:data:add')")
    @Log(title = "BA设备数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody IbmsBaData ibmsBaData) {
        return toAjax(ibmsBaDataService.save(ibmsBaData));
    }

    /**
     * 修改BA设备数据
     */
    @ApiOperation("修改BA设备数据")
    @PreAuthorize("@ss.hasPermi('ba:data:edit')")
    @Log(title = "BA设备数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody IbmsBaData ibmsBaData) {
        return toAjax(ibmsBaDataService.updateById(ibmsBaData));
    }

    /**
     * 删除BA设备数据
     */
    @ApiOperation("删除BA设备数据")
    @PreAuthorize("@ss.hasPermi('ba:data:remove')")
    @Log(title = "BA设备数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ibmsBaDataService.removeBatchByIds(Arrays.asList(ids)));
    }


    @GetMapping("/baFlow")
    public AjaxResult BaFlow() {
        return AjaxResult.success(ibmsBaDataMapper.baFlow());
    }



}
